package com.es;

import java.util.List;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

public class C {

	public static void main(String[] args) throws MQClientException {
		DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("consumerGroup");
		 
		         consumer.setNamesrvAddr("192.168.0.53:9876");
		         consumer.setInstanceName("consumerInstance");
		         consumer.subscribe("topicTest", "tagA");
		 
		         consumer.registerMessageListener(new MessageListenerConcurrently() {
		               

						@Override
						public ConsumeConcurrentlyStatus consumeMessage(
								List<MessageExt> msgs,
								ConsumeConcurrentlyContext context) {

		                     for (MessageExt msg : msgs) {
		                         System.out.println(new String(msg.getTopic()));
		                         System.out.println(new String(msg.getTags()));
		                         System.out.println("=== " + new String(msg.getBody()));
		                     }
		 
		                     return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
		                 
						}
		             });
		         consumer.start();
		         System.out.println("Consumer Started.");
	}

}
